package com.lastproject.ejb.entities;

import java.io.Serializable;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.NamedNativeQueries;
import javax.persistence.NamedNativeQuery;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.validation.constraints.NotNull;

/**
 * Entity implementation class for Entity: ReviewContent
 * 
 */
@Entity
@NamedQueries(value = {
		@NamedQuery(name = "ReviewContent.findContent", query = "SELECT rc.content FROM ReviewContent rc where rc.book = :book"),
		@NamedQuery(name = "ReviewContent.findByBook", query = "SELECT rc FROM ReviewContent rc where rc.book = :book") })
@NamedNativeQueries(value = { @NamedNativeQuery(name = "ReviewContent.hasCriticsReview", query = "Select count(*) from ReviewContent where bookId = ? and content is not null"), })
public class ReviewContent implements Serializable {

	private static final long serialVersionUID = 5508746609454297766L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private int id;

	@OneToOne(optional = false, cascade = CascadeType.REMOVE)
	@JoinColumn(name = "bookId", referencedColumnName = "id", unique = true, nullable = false)
	@NotNull
	private Book book;

	@Basic(fetch = FetchType.LAZY)
	@Lob
	@Column(nullable = false, columnDefinition = "LONGBLOB NOT NULL")
	@NotNull
	private byte[] content;

	public ReviewContent() {
		super();
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public byte[] getContent() {
		return content;
	}

	public void setContent(byte[] content) {
		this.content = content;
	}

	public Book getBook() {
		return book;
	}

	public void setBook(Book book) {
		this.book = book;
	}

}
